﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 

using System.Collections;
using System.Collections.Generic;
using Fulcrum.ControlGenerator;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests.ControlGenerator
{
    [TestClass]
    public class AttachedDependencyPropertyDataContextTests
    {
        public AttachedDependencyPropertyDataContextTests()
        {
            // nothing
        }

        [TestMethod]
        public void TestCoerceValue()
        {
            var config = CreateMockConfig();
            config.CoerceValue = true;

            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual(true, attachedDependencyProperty.CoerceValue);
        }

        [TestMethod]
        public void TestDefaultValue()
        {
            var config = CreateMockConfig();
            config.DefaultValue = "1";

            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual("1", attachedDependencyProperty.DefaultValue);
        }

        [TestMethod]
        public void TestDependencyPropertyKeyName()
        {
            var config = CreateMockConfig();
            config.IsReadOnly = true;
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual("FooPropertyKey", attachedDependencyProperty.DependencyPropertyKeyName);
        }

        [TestMethod]
        public void TestDependencyPropertyName()
        {
            var config = CreateMockConfig();
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual("FooProperty", attachedDependencyProperty.DependencyPropertyName);
        }

        [TestMethod]
        public void TestGetMethodName()
        {
            var config = CreateMockConfig();
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual("GetFoo", attachedDependencyProperty.GetMethodName);
        }

        [TestMethod]
        public void TestGetMethodSummary()
        {
            var config = CreateMockConfig();
            config.GetMethodSummary = "a summary";
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual("a summary", attachedDependencyProperty.GetMethodSummary);
        }

        [TestMethod]
        public void TestIsReadOnly()
        {
            var config = CreateMockConfig();
            config.IsReadOnly = true;
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual(true, attachedDependencyProperty.IsReadOnly);
        }
        [TestMethod]
        public void TestMetadataOptions()
        {
            var config = CreateMockConfig();
            config.MetadataOptions = new string[] { "one", "two" };
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreNotSame(config.MetadataOptions, attachedDependencyProperty.MetadataOptions);
            CollectionAssert.AreEqual((ICollection)config.MetadataOptions, (ICollection)attachedDependencyProperty.MetadataOptions);
        }

        [TestMethod]
        public void TestName()
        {
            var config = CreateMockConfig();
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual("Foo", attachedDependencyProperty.Name);
        }

        [TestMethod]
        public void TestSetMethodName()
        {
            var config = CreateMockConfig();
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual("SetFoo", attachedDependencyProperty.SetMethodName);
        }

        [TestMethod]
        public void TestSetMethodSummary()
        {
            var config = CreateMockConfig();
            config.SetMethodSummary = "a summary";
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual("a summary", attachedDependencyProperty.SetMethodSummary);
        }

        [TestMethod]
        public void TestStaticChangedMethodName()
        {
            var config = CreateMockConfig();
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual("FooProperty_PropertyChanged", attachedDependencyProperty.StaticChangedMethodName);
        }

        [TestMethod]
        public void TestStaticCoerceMethodName()
        {
            var config = CreateMockConfig();
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual("FooProperty_CoerceProperty", attachedDependencyProperty.StaticCoerceMethodName);
        }

        [TestMethod]
        public void TestStaticPartialValidateMethodName()
        {
            var config = CreateMockConfig();
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual("FooProperty_ValidatePropertyImplementation", attachedDependencyProperty.StaticPartialValidateMethodName);
        }

        [TestMethod]
        public void TestStaticValidateMethodName()
        {
            var config = CreateMockConfig();
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual("FooProperty_ValidateProperty", attachedDependencyProperty.StaticValidateMethodName);
        }

        [TestMethod]
        public void TestType()
        {
            var config = CreateMockConfig();
            config.Type = "EventArgs";
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual("EventArgs", attachedDependencyProperty.Type);
        }

        [TestMethod]
        public void TestValidateValue()
        {
            var config = CreateMockConfig();
            config.ValidateValue = true;
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual(true, attachedDependencyProperty.ValidateValue);
        }

        [TestMethod]
        public void TestVisibility()
        {
            var config = CreateMockConfig();
            config.Visibility = PropertyVisibility.Private;
            var attachedDependencyProperty = new AttachedDependencyPropertyDataContext(config);

            Assert.AreEqual(PropertyVisibility.Private, attachedDependencyProperty.Visibility);
        }

        private static MockAttachedDependencyPropertyConfiguration CreateMockConfig()
        {
            var config = new MockAttachedDependencyPropertyConfiguration();

            config.Name = "Foo";
            config.MetadataOptions = new List<string>();

            return config;
        }
    }
}
